//应用static的不可更改和对象之间共享的特性  练习实现一个链表
//定义链表头节点head为静态变量
#include<iostream>
using namespace std; 

class List
{
public:
    List(int d) //构造 (1)结点赋值(2)结点链接成链
        :data(d)
    {
        if(head == NULL)
        {
            this->next = NULL;
            head = this;
        }
        else
        {
            //连接起来
            this->next = head;
            head = this;
        }
    }
    static void dis()
    {
        List *ph = head;
        while(ph)
        {
            cout<<ph->data<<endl;
            ph = ph->next;
        }
    }
private:
    int data;
    List *next;
    static List *head; //head 头节点是不可更改的啊
};

List * List::head = NULL;



int main ()
{
    List a(1),b(2),c(3);
    List::dis();
    return 0;
}